home *** CD-ROM | disk | FTP | other *** search
- Starting with the beta Genki 6, the kernel enforces
- a little more strictly certain rules on how
- kernel add-ons like drivers and bus_managers use
- spinlocks and disable interrupts. Here's a quick
- reminder about the basic principles. Don't hesitate
- to discuss it with us at devinfo@be.com.
-
-
- synchronization: semaphores vs. spinlocks:
- ------------------------------------------
-
- Semaphores should be used whenever possible,
- because they do not incur busy waiting. The
- only reason to use spinlocks is for critical
- sections executed by interrupt handlers.
- It is a very bad programming error to acquire
- a semaphore in an interrupt handler. This
- makes spinlock the only alternative available
- at interrupt time.
-
- Spinlock-protected critical sections should
- be executed with interrupts disabled. It is
- not necessary to explicitly disable interrupts
- in spinlock-protected critical sections used only
- by interrupt handlers because they are invoked
- with interrupts already disabled.
-
- There are very few things that may be done in
- a spinlock-protected critical section. All the
- restrictions that apply to code run with interrupts
- disabled apply here (see list below under next section).
- And other rules apply in addition. Here's the list of
- what can be done:
- - touch hardware registers (through bus managers
- hooks)
- - touch memory that is locked down. No memory can
- be allocated!
- - call the following functions:
- kernel:
- . system_time()
- . atomic_XXX()
- bus managers:
- IO functions: read_io_XX(), write_io_XX()
-
- disabling interrupts:
- ---------------------
-
- Disable interrupts only around critical sections
- protected by spinlocks (see discussion on spinlocks).
- If you think you need to disable interrupts for
- another reason, discuss it with us at devsupport@be.com.
-
- Disable interrupts for the shortest time possible -- never
- longer than 50us. Because interrupt handlers are
- executed implicitely with interrupts disabled, they
- should not run than 50 us as well.
-
- No blocking call can be made when interrupts are disabled.
- In addition to what you can do in spinlock-protected
- sections, here a list of the calls you can make:
- - release_sem_etc() with B_DO_NO_RESCHEDULE as flags.
- - get_sem_count()
- - add_timer(), cancel_timer()
- - dprintf()
-
- If you feel you need to call a function that is not in
- this list, discuss it with us at devinfo@be.com.
-